home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 4 / Macwelt DVD 4.cdr / Entwickler / Mac-OS / oxygen / oxygen.app / Contents / Resources / Java / jh.jar / javax / help / HelpSet.class (.txt) < prev    next >
Encoding:
Java Class File  |  2002-06-24  |  10.3 KB  |  423 lines

  1. package javax.help;
  2.  
  3. import com.sun.java.help.impl.XmlReader;
  4. import java.beans.PropertyChangeSupport;
  5. import java.io.Reader;
  6. import java.net.URL;
  7. import java.net.URLConnection;
  8. import java.util.Enumeration;
  9. import java.util.Hashtable;
  10. import java.util.Locale;
  11. import java.util.Vector;
  12. import javax.help.Map.ID;
  13. import javax.help.event.EventListenerList;
  14. import javax.help.event.HelpSetEvent;
  15. import javax.help.event.HelpSetListener;
  16.  
  17. public class HelpSet {
  18.    private static String errorMsg = null;
  19.    protected EventListenerList listenerList;
  20.    public static final String publicIDString = "-//Sun Microsystems Inc.//DTD JavaHelp HelpSet Version 1.0//EN";
  21.    public static final Object implRegistry = new StringBuffer("HelpSet.implRegistry");
  22.    public static final String helpBrokerClass = "helpBroker/class";
  23.    public static final String helpBrokerLoader = "helpBroker/loader";
  24.    public static final Object kitTypeRegistry = new StringBuffer("JHelpViewer.kitTypeRegistry");
  25.    public static final Object kitLoaderRegistry = new StringBuffer("JHelpViewer.kitLoaderRegistry");
  26.    private String title;
  27.    private Map map;
  28.    private TryMap combinedMap;
  29.    private URL helpset;
  30.    private String homeID;
  31.    private Locale locale;
  32.    private ClassLoader loader;
  33.    private Vector views;
  34.    private Vector helpsets;
  35.    private static HelpBroker defaultHelpBroker;
  36.    private Vector subHelpSets;
  37.    private static Hashtable defaultKeys;
  38.    private Hashtable localKeys;
  39.    private PropertyChangeSupport changes;
  40.    private static final boolean debug = false;
  41.    // $FF: synthetic field
  42.    static Class class$javax$help$event$HelpSetListener;
  43.    // $FF: synthetic field
  44.    static Class class$javax$help$HelpSet;
  45.  
  46.    public HelpSet(ClassLoader var1) {
  47.       this.listenerList = new EventListenerList();
  48.       this.locale = Locale.getDefault();
  49.       this.views = new Vector();
  50.       this.subHelpSets = new Vector();
  51.       this.localKeys = new Hashtable();
  52.       this.changes = new PropertyChangeSupport(this);
  53.       this.helpsets = new Vector();
  54.       this.loader = var1;
  55.    }
  56.  
  57.    public HelpSet() {
  58.       this.listenerList = new EventListenerList();
  59.       this.locale = Locale.getDefault();
  60.       this.views = new Vector();
  61.       this.subHelpSets = new Vector();
  62.       this.localKeys = new Hashtable();
  63.       this.changes = new PropertyChangeSupport(this);
  64.       this.helpsets = new Vector();
  65.       this.loader = null;
  66.    }
  67.  
  68.    public HelpSet(ClassLoader var1, URL var2) throws HelpSetException {
  69.       this(var1);
  70.       this.helpset = var2;
  71.       DefaultHelpSetFactory var3 = new DefaultHelpSetFactory();
  72.       this.parseInto(var2, var3);
  73.       HelpSet var4 = var3.parsingEnded(this);
  74.       if (var4 == null) {
  75.          throw new HelpSetException("Could not parse\n" + errorMsg);
  76.       }
  77.    }
  78.  
  79.    public static URL findHelpSet(ClassLoader var0, String var1, String var2, Locale var3) {
  80.       return HelpUtilities.getLocalizedResource(var0, var1, var2, var3, true);
  81.    }
  82.  
  83.    public static URL findHelpSet(ClassLoader var0, String var1, Locale var2) {
  84.       String var3;
  85.       String var4;
  86.       if (var1.endsWith(".hs")) {
  87.          var3 = var1.substring(0, var1.length() - 3);
  88.          var4 = ".hs";
  89.       } else {
  90.          var3 = var1;
  91.          var4 = ".hs";
  92.       }
  93.  
  94.       return findHelpSet(var0, var3, var4, var2);
  95.    }
  96.  
  97.    public static URL findHelpSet(ClassLoader var0, String var1) {
  98.       return findHelpSet(var0, var1, Locale.getDefault());
  99.    }
  100.  
  101.    public HelpBroker createHelpBroker() {
  102.       Object var1 = null;
  103.       String var2 = (String)this.getKeyData(implRegistry, "helpBroker/class");
  104.       ClassLoader var3 = (ClassLoader)this.getKeyData(implRegistry, "helpBroker/loader");
  105.       if (var3 == null) {
  106.          var3 = this.getLoader();
  107.       }
  108.  
  109.       try {
  110.          Class var4;
  111.          if (var3 != null) {
  112.             var4 = var3.loadClass(var2);
  113.          } else {
  114.             var4 = Class.forName(var2);
  115.          }
  116.  
  117.          var6 = (HelpBroker)var4.newInstance();
  118.       } catch (Throwable var5) {
  119.          var6 = null;
  120.       }
  121.  
  122.       if (var6 != null) {
  123.          var6.setHelpSet(this);
  124.       }
  125.  
  126.       return var6;
  127.    }
  128.  
  129.    public void add(HelpSet var1) {
  130.       debug("add(" + var1 + ")");
  131.       this.helpsets.addElement(var1);
  132.       this.fireHelpSetAdded(this, var1);
  133.       this.combinedMap = null;
  134.    }
  135.  
  136.    public boolean remove(HelpSet var1) {
  137.       if (this.helpsets.removeElement(var1)) {
  138.          this.fireHelpSetRemoved(this, var1);
  139.          this.combinedMap = null;
  140.          return true;
  141.       } else {
  142.          return false;
  143.       }
  144.    }
  145.  
  146.    public Enumeration getHelpSets() {
  147.       return this.helpsets.elements();
  148.    }
  149.  
  150.    public boolean contains(HelpSet var1) {
  151.       if (var1 == this) {
  152.          return true;
  153.       } else {
  154.          Enumeration var2 = this.helpsets.elements();
  155.  
  156.          while(var2.hasMoreElements()) {
  157.             HelpSet var3 = (HelpSet)var2.nextElement();
  158.             if (var3.contains(var1)) {
  159.                return true;
  160.             }
  161.          }
  162.  
  163.          return false;
  164.       }
  165.    }
  166.  
  167.    public void addHelpSetListener(HelpSetListener var1) {
  168.       debug("addHelpSetListener(" + var1 + ")");
  169.       this.listenerList.add(class$javax$help$event$HelpSetListener == null ? (class$javax$help$event$HelpSetListener = class$("javax.help.event.HelpSetListener")) : class$javax$help$event$HelpSetListener, var1);
  170.    }
  171.  
  172.    public void removeHelpSetListener(HelpSetListener var1) {
  173.       this.listenerList.remove(class$javax$help$event$HelpSetListener == null ? (class$javax$help$event$HelpSetListener = class$("javax.help.event.HelpSetListener")) : class$javax$help$event$HelpSetListener, var1);
  174.    }
  175.  
  176.    protected void fireHelpSetAdded(Object var1, HelpSet var2) {
  177.       Object[] var3 = this.listenerList.getListenerList();
  178.       HelpSetEvent var4 = null;
  179.  
  180.       for(int var5 = var3.length - 2; var5 >= 0; var5 -= 2) {
  181.          if (var3[var5] == (class$javax$help$event$HelpSetListener == null ? (class$javax$help$event$HelpSetListener = class$("javax.help.event.HelpSetListener")) : class$javax$help$event$HelpSetListener)) {
  182.             if (var4 == null) {
  183.                var4 = new HelpSetEvent(this, var2, 0);
  184.             }
  185.  
  186.             ((HelpSetListener)var3[var5 + 1]).helpSetAdded(var4);
  187.          }
  188.       }
  189.  
  190.    }
  191.  
  192.    protected void fireHelpSetRemoved(Object var1, HelpSet var2) {
  193.       Object[] var3 = this.listenerList.getListenerList();
  194.       HelpSetEvent var4 = null;
  195.  
  196.       for(int var5 = var3.length - 2; var5 >= 0; var5 -= 2) {
  197.          if (var3[var5] == (class$javax$help$event$HelpSetListener == null ? (class$javax$help$event$HelpSetListener = class$("javax.help.event.HelpSetListener")) : class$javax$help$event$HelpSetListener)) {
  198.             if (var4 == null) {
  199.                var4 = new HelpSetEvent(this, var2, 1);
  200.             }
  201.  
  202.             ((HelpSetListener)var3[var5 + 1]).helpSetRemoved(var4);
  203.          }
  204.       }
  205.  
  206.    }
  207.  
  208.    public String getTitle() {
  209.       return this.title == null ? "" : this.title;
  210.    }
  211.  
  212.    public void setTitle(String var1) {
  213.       String var2 = this.title;
  214.       this.title = var1;
  215.       this.changes.firePropertyChange("title", var2, var1);
  216.    }
  217.  
  218.    public Locale getLocale() {
  219.       return this.locale;
  220.    }
  221.  
  222.    private void setLocale(Locale var1) {
  223.       Locale var2 = this.locale;
  224.       this.locale = var1;
  225.       this.changes.firePropertyChange("locale", var2, this.locale);
  226.    }
  227.  
  228.    public Map.ID getHomeID() {
  229.       if (this.homeID == null) {
  230.          return null;
  231.       } else {
  232.          try {
  233.             return ID.create(this.homeID, this);
  234.          } catch (Exception var2) {
  235.             return null;
  236.          }
  237.       }
  238.    }
  239.  
  240.    public void setHomeID(String var1) {
  241.       this.homeID = var1;
  242.       this.changes.firePropertyChange("homeID", var1, var1);
  243.    }
  244.  
  245.    public Map getCombinedMap() {
  246.       if (this.combinedMap == null) {
  247.          this.combinedMap = new TryMap();
  248.          if (this.map != null) {
  249.             this.combinedMap.add(this.map);
  250.          }
  251.  
  252.          Enumeration var1 = this.helpsets.elements();
  253.  
  254.          while(var1.hasMoreElements()) {
  255.             HelpSet var2 = (HelpSet)var1.nextElement();
  256.             this.combinedMap.add(var2.getLocalMap());
  257.          }
  258.       }
  259.  
  260.       return this.combinedMap;
  261.    }
  262.  
  263.    public Map getLocalMap() {
  264.       return this.map;
  265.    }
  266.  
  267.    public void setLocalMap(Map var1) {
  268.       this.map = var1;
  269.    }
  270.  
  271.    public URL getHelpSetURL() {
  272.       return this.helpset;
  273.    }
  274.  
  275.    public ClassLoader getLoader() {
  276.       return this.loader;
  277.    }
  278.  
  279.    public NavigatorView[] getNavigatorViews() {
  280.       NavigatorView[] var1 = new NavigatorView[this.views.size()];
  281.       this.views.copyInto(var1);
  282.       return var1;
  283.    }
  284.  
  285.    public NavigatorView getNavigatorView(String var1) {
  286.       debug("getNavigatorView(" + var1 + ")");
  287.  
  288.       for(int var2 = 0; var2 < this.views.size(); ++var2) {
  289.          NavigatorView var3 = (NavigatorView)this.views.elementAt(var2);
  290.          if (var3.getName().equals(var1)) {
  291.             debug("  = " + var3);
  292.             return var3;
  293.          }
  294.       }
  295.  
  296.       debug("  = null");
  297.       return null;
  298.    }
  299.  
  300.    public String toString() {
  301.       return this.getTitle();
  302.    }
  303.  
  304.    public static HelpSet parse(URL var0, ClassLoader var1, HelpSetFactory var2) {
  305.       HelpSet var3 = new HelpSet(var1);
  306.       var3.helpset = var0;
  307.       var3.parseInto(var0, var2);
  308.       return var2.parsingEnded(var3);
  309.    }
  310.  
  311.    public void parseInto(URL var1, HelpSetFactory var2) {
  312.       try {
  313.          URLConnection var4 = var1.openConnection();
  314.          Reader var3 = XmlReader.createReader(var4);
  315.          var2.parsingStarted(var1);
  316.          (new HelpSetParser(var2)).parseInto(var3, this);
  317.          var3.close();
  318.       } catch (Exception var6) {
  319.          var2.reportMessage("Got an IOException (" + var6.getMessage() + ")", false);
  320.       }
  321.  
  322.       for(int var7 = 0; var7 < this.subHelpSets.size(); ++var7) {
  323.          HelpSet var5 = (HelpSet)this.subHelpSets.elementAt(var7);
  324.          this.add(var5);
  325.       }
  326.  
  327.    }
  328.  
  329.    protected void addView(NavigatorView var1) {
  330.       this.views.addElement(var1);
  331.    }
  332.  
  333.    protected void addSubHelpSet(HelpSet var1) {
  334.       this.subHelpSets.addElement(var1);
  335.    }
  336.  
  337.    public Object getKeyData(Object var1, String var2) {
  338.       Object var3 = null;
  339.       Hashtable var4 = (Hashtable)this.localKeys.get(var1);
  340.       if (var4 != null) {
  341.          var3 = var4.get(var2);
  342.       }
  343.  
  344.       if (var3 == null) {
  345.          var4 = (Hashtable)defaultKeys.get(var1);
  346.          if (var4 != null) {
  347.             var3 = var4.get(var2);
  348.          }
  349.       }
  350.  
  351.       return var3;
  352.    }
  353.  
  354.    public void setKeyData(Object var1, String var2, Object var3) {
  355.       Hashtable var4 = (Hashtable)this.localKeys.get(var1);
  356.       if (var4 == null) {
  357.          var4 = new Hashtable();
  358.          this.localKeys.put(var1, var4);
  359.       }
  360.  
  361.       var4.put(var2, var3);
  362.    }
  363.  
  364.    private static void setDefaultKeyData(Object var0, String var1, Object var2) {
  365.       if (defaultKeys == null) {
  366.          defaultKeys = new Hashtable();
  367.       }
  368.  
  369.       Hashtable var3 = (Hashtable)defaultKeys.get(var0);
  370.       if (var3 == null) {
  371.          var3 = new Hashtable();
  372.          defaultKeys.put(var0, var3);
  373.       }
  374.  
  375.       var3.put(var1, var2);
  376.    }
  377.  
  378.    private static void debug(String var0) {
  379.    }
  380.  
  381.    // $FF: synthetic method
  382.    static Class class$(String var0) {
  383.       try {
  384.          return Class.forName(var0);
  385.       } catch (ClassNotFoundException var2) {
  386.          throw new NoClassDefFoundError(var2.getMessage());
  387.       }
  388.    }
  389.  
  390.    // $FF: synthetic method
  391.    static void access$000(String var0) {
  392.       debug(var0);
  393.    }
  394.  
  395.    // $FF: synthetic method
  396.    static String access$100() {
  397.       return errorMsg;
  398.    }
  399.  
  400.    // $FF: synthetic method
  401.    static String access$102(String var0) {
  402.       errorMsg = var0;
  403.       return var0;
  404.    }
  405.  
  406.    // $FF: synthetic method
  407.    static void access$200(HelpSet var0, Locale var1) {
  408.       var0.setLocale(var1);
  409.    }
  410.  
  411.    static {
  412.       setDefaultKeyData(implRegistry, "helpBroker/class", "javax.help.DefaultHelpBroker");
  413.       setDefaultKeyData(kitTypeRegistry, "text/html", "com.sun.java.help.impl.CustomKit");
  414.       ClassLoader var0 = (class$javax$help$HelpSet == null ? (class$javax$help$HelpSet = class$("javax.help.HelpSet")) : class$javax$help$HelpSet).getClassLoader();
  415.       if (var0 != null) {
  416.          setDefaultKeyData(implRegistry, "helpBroker/loader", var0);
  417.          setDefaultKeyData(kitLoaderRegistry, "text/html", var0);
  418.       }
  419.  
  420.       defaultHelpBroker = null;
  421.    }
  422. }
  423.